<template>
	<view>
		<uni-section title="">
			<view class="example">
				<!-- 基础用法，不包含校验规则 -->
				<uni-forms ref="floorForm" :modelValue="form" label-position="left" label-width="120px"
					:rules="floorRules">
					<uni-forms-item label="建筑物" class="form_item" required name="bgId">
						<uni-data-select v-model="form.bgId" placeholder="请选择建筑物"
							:localdata="bgList.map(item => ({value: item.id, text: item.bdName}))"></uni-data-select>
					</uni-forms-item>
					<uni-forms-item label="楼层名称" class="form_item" required name="floorName">
						<uni-easyinput v-model="form.floorName" placeholder="请输入楼层名称" />
					</uni-forms-item>
					<uni-forms-item label="楼层索引" class="form_item" required name="floorIndex">
						<uni-easyinput v-model="form.floorIndex" placeholder="请输入楼层索引" />
					</uni-forms-item>
					<uni-forms-item label="楼层面积" class="form_item" required name="floorArea">
						<uni-easyinput v-model="form.floorArea" placeholder="请输入楼层面积" />
					</uni-forms-item>
					<uni-forms-item label="房间数量" class="form_item" name="floorRoomCount">
						<uni-easyinput v-model="form.floorRoomCount" placeholder="请输入房间数量" />
					</uni-forms-item>
					<uni-forms-item label="楼层高度" class="form_item" name="floorHeight">
						<uni-easyinput v-model="form.floorHeight" placeholder="请输入楼层高度" />
					</uni-forms-item>
					<uni-forms-item label="是否是避难层" class="form_item" name="floorIsRefuge">
						<uni-data-checkbox v-model="form.floorIsRefuge" :localdata="floorIsRefugeList" />
					</uni-forms-item>
					<uni-forms-item label="备注" class="form_item" name="remark">
						<uni-easyinput v-model="form.remark" placeholder="请输入备注" />
					</uni-forms-item>
				</uni-forms>
				<button type="primary" @click="submit('floorForm')">提交</button>
			</view>
		</uni-section>
	</view>
</template>

<script>
	import {
		getDicts
	} from "@/api/system/dict/data.js"
	import {
		listUnit,
	} from "@/api/system/unit"
	import {listFloor, getFloor, delFloor, addFloor, updateFloor, floorPush} from "@/api/system/floor"
	import {
		listBuilding,
	} from "@/api/system/building"
	import config from '@/config'
	import {
		getToken
	} from '@/utils/auth'

	export default {
		data() {
			return {
				bgList: [], //单位list
				floorIsRefugeList: [{
					text: '是',
					value: 0
				}, {
					text: '否',
					value: 1
				}],
				form: {},
				floorRules: {
					bgId: {
						rules: [{
							required: true,
							errorMessage: '建筑物不能为空'
						}]
					},
					floorName: {
						rules: [{
							required: true,
							errorMessage: '楼层名称不能为空'
						}]
					},
					floorIndex: {
						rules: [{
							required: true,
							errorMessage: '楼层索引不能为空'
						}]
					},
					floorArea: {
						rules: [{
							required: true,
							errorMessage: '楼层面积不能为空'
						}]
					},
				},
			}
		},
		created() {
			this.getBuilding()
		},
		methods: {
			/** 查询单位 */
			getBuilding(row) {
				listBuilding({
					pageNum: 1,
					pageSize: 999999,
				}).then(response => {
					this.bgList = response.rows

				})
			},
			submit(ref) {
				this.$refs['floorForm'].validate().then(res => {
					addFloor(this.form).then(response => {
						this.$modal.msgSuccess("新增成功！");
						this.form = {}
						uni.reLaunch({
							url: '/pages/system/floor/index'
						});
					})
				}).catch(err => {
					console.log('err', err);
				})
			},

		}
	}
</script>

<style>
	.example {
		padding: 15px;
		background-color: #fff;
	}

	.form_item {
		margin-bottom: 15px;
	}
</style>